﻿
@using KC.Web.Admin.Constants
@{
    ViewBag.Title = "开通应用错误日志";
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
<div id="addDialog" data-options="close:true">
</div>
<div id="toolbar">
    <div>
        错误类型：
        @Html.DropDownList("OpenServerType", (IEnumerable<SelectListItem>)ViewBag.OpenServerTypeList, new { @id = "OpenServerType", @class = "easyui-combobox", @style = "width: 150px;height:26px;" })
        租户名称：
        <input id="searchText" class="easyui-textbox" name="searchText" data-options="prompt: '请输入租户名称'" />
        <a href="javascript:void(0)" onclick="reloadDatagrid()" class="easyui-linkbutton" data-options="iconCls:'fa fa-search'">查询</a>
        <a href="javascript:void(0)" onclick="RefreshSearch()" class="easyui-linkbutton" data-options="iconCls:'fa fa-refresh'">刷新</a>
    </div>
</div>
<table id="datagrid" style=" height:408px;"></table>
@section scripts
    {
    <script type="text/javascript">
        function reloadDatagrid() {
            var openServerType = $("#OpenServerType").combobox("getValue");
            $("#datagrid").datagrid("load", {
                tenantDisplayName: $("#searchText").searchbox("getValue"),
                openServerType: openServerType,
            });
        };
        function RefreshSearch() {
            $('#searchText').searchbox("setValue", '');
            $("#OpenServerType").combobox("setValue","");
            reloadDatagrid();
        }

        $(function () {
            //资源类型
            $('#OpenServerType').combobox(
            {
                editable: false,
                onSelect: function () {
                }
            });

            $("#datagrid").datagrid({
                url: 'LoadTenantErrorlog',
                method: 'get',
                striped: true,
                fitColumns: true,
                rownumbers: true,
                singleSelect: true,
                pagination: true,
                nowrap: false,
                fit: true,
                pageSize: 10,
                pageList: [10, 20, 50, 100],
                showFooter: false,
                toolbar: "#toolbar",
                //toolbar: [{ text: document.getElementById('toolbar') }],
                columns: [[
                    { field: "TenantName", title: "租户代码", width: 65 },
                    { field: "TenantDisplayName", title: "租户名称", width: 67 },
                    { field: "OpenServerTypeName", title: "错误类型", width: 70 },
                    { field: "TypeName", title: "日志类型", width: 30 },
                    { field: "OperateDate", title: "日期", sortable: true, formatter: Common.DateFormatter, width: 50 },
                    {
                        field: '操作', title: '操作', width: 100, sorter: function numberSort(a, b) { return a.localeCompare(b); },
                        formatter: function (value, row, index) {
                            var tdContext = '';
                            tdContext += '<button onclick="Detailed (\'' + row.ProcessLogId + '\',\'' + row.Fid + '\' )">详情</button>';

                            if (row.IsShowUpgradeDbBtn)
                                tdContext += '<button onclick="UpgradeTenantDatabase (\'' + row.TenantId + '\',\'' + row.ProcessLogId + '\' )">更新数据库</button>';
                            //if (row.IsShowRollbackDbBtn)
                            //tdContext += '<button onclick="RollBackTenantDataBaseUrl (\'' + row.TenantId+ '\',\'' + row.ProcessLogId + '\' )">回滚数据库</button>';
                            if (row.IsShowResendOpenAppEmailBtn)
                                tdContext += '<button onclick="ResendOpenEmail (\'' + row.TenantId + '\',\'' + row.ProcessLogId + '\' )">重新发送开通邮件</button>';
                            return tdContext;
                        },
                    }]]
            });
        });

        function Detailed(id) {
            var dialog = $.easyui.showDialog({
                title: "查看详情",
                width: 500,
                height: 460,
                href: 'GetTenantErrorlogForm' + "?id=" + id,
                modal: true,
                topMost: false,
                enableHeaderContextMenu: false,
                enableApplyButton: false,
                onLoad: function () {
                    var f = $(this), ret = $.fn.dialog.defaults.onLoad();
                    f.form("disableValidation").form("enableValidation");
                    return ret;
                }
            });
        }

        var UpgradeTenantDatabaseUrl = '@Url.Action(ActionName.Tenant.UpgradeTenantDatabase, ControllerName.Tenant)';
        function UpgradeTenantDatabase(tenantId, id) {
            $.messager.confirm('系统提示', '是否确定重新更新该租户的数据库?', function (r) {
                if (r) {
                    $.easyui.loading({ msg: '正在保存数据，请稍等...' });
                    $.post(UpgradeTenantDatabaseUrl, { tenantId: tenantId, id: id }, function (data) {
                        $.easyui.loaded();
                        if (data.success) {
                            if (data.Result) {
                                $('#datagrid').datagrid('reload');
                                $.messager.showInfoCenter('系统提示', '更新该租户的数据库成功。', 1000);
                            } else {
                                $.messager.showErrorCenter('错误消息', '更新该租户的数据库失败。', 5000);
                            }
                        } else {
                            $.data.showErrorCenter('错误消息', data.message, 5000);
                        }
                    }, 'json');
                }
            });
        }

        var RollBackTenantDataBaseUrl = '@Url.Action(ActionName.Tenant.RollBackTenantDataBase, ControllerName.Tenant)';
        function RollBackTenantDataBase(tenantId, id) {
            $.messager.confirm('确认', '是否确定重新回滚该租户的数据库?', function (r) {
                if (r) {
                    $.easyui.loading({ msg: '正在保存数据，请稍等...' });
                    $.post(RollBackTenantDataBaseUrl, { tenantId: tenantId, id: id }, function (data) {
                        $.easyui.loaded();
                        if (data.success) {
                            if (data.Result) {
                                $('#datagrid').datagrid('reload');
                                $.messager.showInfoCenter('系统提示', '回滚该租户的数据库成功。', 1000);
                            } else {
                                $.messager.showErrorCenter('错误消息', '回滚该租户的数据库失败。', 5000);
                            }
                        } else {
                            $.data.showErrorCenter('错误消息', data.message, 5000);
                        }
                    }, 'json');
                }
            });
        }

        var ResendOpenEmailUrl = '@Url.Action(ActionName.Tenant.ReSendOpenAppEmail, ControllerName.Tenant)';
        function ResendOpenEmail(tenantId, id) {
            $.messager.confirm('确认', '是否确定要重新发送开通应用的邮件?', function (r) {
                if (r) {
                    $.easyui.loading({ msg: '正在保存数据，请稍等...' });
                    $.post(ResendOpenEmailUrl, { tenantId: tenantId, id: id }, function (data) {
                        $.easyui.loaded();
                        if (data.success) {
                            if (data.Result) {
                                $('#datagrid').datagrid('reload');
                                $.messager.showInfoCenter('系统提示', '重新发送开通应用的邮件成功。', 1000);
                            } else {
                                $.messager.showErrorCenter('错误消息', '重新发送开通应用的邮件失败。', 5000);
                            }
                        } else {
                            $.data.showErrorCenter('错误消息', data.message, 5000);
                        }
                    }, 'json');
                }
            });
        }
    </script>
}


